/*
 * BookUpdate.java
 *
 * Created on __DATE__, __TIME__
 */

package Consult.view;

import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


/**
 *
 * @author  __USER__
 */
public class BookUpdate extends javax.swing.JFrame {
	/**
	 * ���к�
	 */
	private static final long serialVersionUID = 1L;

	BookModel bookModel;

	/** Creates new form BookUpdate */
	public BookUpdate() {
		initComponents();
		this.setBounds(150, 50, 1050, 650);
		//���ñ���
		setBackgroudImage();
		//�����С���ɱ�
		this.setResizable(false);
		//���ô���ͼ��
		Toolkit tool = this.getToolkit(); //�õ�һ��Toolkit����
		Image myimage = tool.getImage("img/3.png"); //��tool��ȡͼ��
		this.setIconImage(myimage);

	}

	/** Creates new form BookUpdate���췽�� */
	public BookUpdate(BookModel bookModel) {
		this.bookModel = bookModel;
		initComponents();
		this.setBounds(150, 50, 1050, 650);
		//���ñ���
		setBackgroudImage();
		//�����С���ɱ�
		this.setResizable(false);

		this.bno.setText(bookModel.getBno());
		this.bname.setText(bookModel.getName());
		this.bauthor.setText(bookModel.getAuthor());
		this.btype.setSelectedItem(bookModel.getTname());
	}

	/** 
	 * ��ʼ��ͼ���޸Ĵ��屳�� 
	 */
	private void setBackgroudImage() {
		((JPanel) this.getContentPane()).setOpaque(false);
		ImageIcon img = new ImageIcon("img/bookupdate.jpg"); // ���ͼƬ  
		JLabel lb_backgroud = new JLabel(img);
		this.getLayeredPane().add(lb_backgroud, new Integer(Integer.MIN_VALUE));
		lb_backgroud.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		bno = new javax.swing.JTextField();
		bname = new javax.swing.JTextField();
		bauthor = new javax.swing.JTextField();
		submit = new javax.swing.JLabel();
		btype = new javax.swing.JComboBox();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("\u56fe\u4e66\u7ba1\u7406\u7cfb\u7edf>\u56fe\u4e66\u7ba1\u7406>\u56fe\u4e66\u4fee\u6539");

		bno.setEditable(false);
		bno.setFont(new java.awt.Font("΢���ź�", 0, 18));
		bno.setBorder(null);

		bname.setFont(new java.awt.Font("΢���ź�", 0, 18));
		bname.setBorder(null);

		bauthor.setFont(new java.awt.Font("΢���ź�", 0, 18));
		bauthor.setBorder(null);

		submit.setFont(new java.awt.Font("����", 0, 30));
		submit.setForeground(new java.awt.Color(255, 255, 255));
		submit.setText("\u63d0\u4ea4");
		submit.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				submitMouseClicked(evt);
			}
		});

		btype.setFont(new java.awt.Font("΢���ź�", 0, 16));
		btype.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"��ѡ��", "�ƻ�", "ɢ��", "��ѧ", "��װ", "��Ȼ", "��ѧ", "����", "����" }));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGap(273, 273, 273)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																btype,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																187,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addGroup(
																layout
																		.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING,
																				false)
																		.addComponent(
																				bauthor,
																				javax.swing.GroupLayout.Alignment.LEADING)
																		.addComponent(
																				bname,
																				javax.swing.GroupLayout.Alignment.LEADING)
																		.addComponent(
																				bno,
																				javax.swing.GroupLayout.Alignment.LEADING,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				244,
																				Short.MAX_VALUE)))
										.addContainerGap(551, Short.MAX_VALUE))
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								layout.createSequentialGroup().addContainerGap(
										517, Short.MAX_VALUE).addComponent(
										submit).addGap(491, 491, 491)));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addGap(200, 200, 200)
						.addComponent(bno,
								javax.swing.GroupLayout.PREFERRED_SIZE, 31,
								javax.swing.GroupLayout.PREFERRED_SIZE).addGap(
								33, 33, 33).addComponent(bname,
								javax.swing.GroupLayout.PREFERRED_SIZE, 31,
								javax.swing.GroupLayout.PREFERRED_SIZE).addGap(
								28, 28, 28).addComponent(bauthor,
								javax.swing.GroupLayout.PREFERRED_SIZE, 31,
								javax.swing.GroupLayout.PREFERRED_SIZE).addGap(
								36, 36, 36).addComponent(btype,
								javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.PREFERRED_SIZE).addGap(
								49, 49, 49).addComponent(submit)
						.addContainerGap(148, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	/**
	 *�ύͼ���޸�
	 */
	private void submitMouseClicked(java.awt.event.MouseEvent evt) {
		String bno = this.bno.getText();
		String bname = this.bname.getText();
		String bauthor = this.bauthor.getText();
		String btype = this.btype.getSelectedItem().toString();
		BookModel book = new BookModel();
		book.setBno(bno);
		book.setName(bname);
		book.setAuthor(bauthor);
		book.setTname(btype);
		book.setLent("��");
		//�ж�ͼ�����Ƿ��ظ�
		//ͼ������
		BookUpdateDao bud = new BookUpdateDao();
		bud.updateBook(book);

		JOptionPane.showMessageDialog(null, "�޸ĳɹ�");
		//��ת��queryServiceҳ��
		new BookManager().setVisible(true);
		//��ת��ر�ԭ��ҳ��
		this.dispose();
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new BookUpdate().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JTextField bauthor;
	private javax.swing.JTextField bname;
	private javax.swing.JTextField bno;
	private javax.swing.JComboBox btype;
	private javax.swing.JLabel submit;
	// End of variables declaration//GEN-END:variables

}